import java.util.Scanner;

public class Test1 {
    //按顺序打印一个数字的每一位（eg:1234打印出1 2 3 4）
    public static void print(int n) {
        if(n < 10) {
            System.out.print(n + " ");
            return;
        }
        print(n / 10);
        System.out.print(n % 10 + " ");
        return;
    }
    //递归求1+2+...+n
    public static int sumNum(int n) {
        if(n == 1){
            return 1;
        }
        return n + sumNum(n-1);
    }
    //递归求输入一个非负整数，返回组成它的数字之和(eg:1729,返回1+7+2+9=19)
    public static int func(int n) {
        if (n < 10) {
            return n;
        }
        return func(n / 10) + (n % 10) ;
    }
    //递归求斐波那契数列的第N项
    public static int fib(int n) {
        if(n == 1) {
            return 0;
        }
        if(n == 2) {
            return 1;
        }
        return fib(n-1) + fib(n-2);
    }
    //非递归实现求斐波那契数列的第N项
    public static int fib2(int n) {
        if(n == 1) {
            return 0;
        }
        if(n == 2) {
            return 1;
        }
        int f1 = 0;
        int f2 = 1;
        int f3 = -1;
        for (int i = 3; i <= n; i++) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }
    public static void main(String[] args) {
        //按顺序打印一个数字的每一位
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        print(num);
        scanner.close();
        //递归求1+2+...+n
        System.out.println();
        System.out.println("===========");
        int ret = sumNum(10);
        System.out.println(ret);
        //递归求输入一个非负整数的各位之和
        System.out.println("===========");
        int tmp = func(1729);
        System.out.println(tmp);
        //斐波那契的数列第N项
        System.out.println("===========");
        System.out.println(fib(1));
        System.out.println(fib(2));
        System.out.println(fib(3));
        System.out.println(fib(4));
        System.out.println(fib(40));
    }
}
